<?php
class tintuc_db extends CI_Model{

    public function __construct()
    {
        $this->load->database();
    }
    
    public function get_tintuc_info($id)
    {
        $query = $this->db->query("SELECT tintuc.ten,loaitin.name,tintuc.noidung,tintuc.id,tintuc.NgayDang,tintuc.LanDoc
                                   FROM tintuc,loaitin
                                   WHERE tintuc.idLoai = loaitin.id
                                   AND AnHien = '1'
                                   AND tintuc.id = '$id'
                                  ");
        return $query->result();
    }
    
    public function set_tintuc_info($idLoai, $ten, $NoiDung, $anhien, $ghichu )
    {
        $query = $this->db->query("INSERT INTO tintuc(id,idLoai,Ten,NoiDung,NgayDang,NgayCapNhat,AnHien,LanDoc,GhiChu)
                                   VALUE ('NULL','".$idLoai."','".$ten."','".$NoiDung."',NOW(),'NULL','".$anhien."','0','".$ghichu."')
                                  ");
        if($query)
            return true;
        else
            return false;
    }
    
    public function update_tintuc_noidung($id,$noidung,$landoc,$loaitin)
    {
        $query = $this->db->query("UPDATE tintuc
                                   SET NoiDung = '$noidung',
                                       LanDoc = $landoc,
                                       idLoai = $loaitin
                                   WHERE id = '$id'");
        if($query)
            return true;
        else
            return false;
    }
    
    public function delete_tintuc($id)
    {
        $query = $this->db->query("DELETE FROM tintuc
                                   WHERE id = '$id'");
        if($query)
            return true;
        else
            return false;
    }
}
?>